<template>
  <div class="leave-management">
    <el-card>
      <template #header>
        <div class="card-header">
          <span>请假管理</span>
          <el-button type="primary" @click="handleAdd">新增请假</el-button>
        </div>
      </template>

      <el-table :data="leaveRecords" style="width: 100%" border>
        <el-table-column prop="name" label="申请人" width="120" />
        <el-table-column prop="type" label="请假类型" width="120">
          <template #default="scope">
            <el-tag :type="getLeaveTypeTag(scope.row.type)">
              {{ scope.row.type }}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="startDate" label="开始时间" width="180" />
        <el-table-column prop="endDate" label="结束时间" width="180" />
        <el-table-column prop="status" label="状态" width="120">
          <template #default="scope">
            <el-tag :type="getStatusTag(scope.row.status)">
              {{ scope.row.status }}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="reason" label="请假原因" />
        <el-table-column label="操作" width="200">
          <template #default="scope">
            <el-button 
              type="primary" 
              link
              @click="handleApprove(scope.row)"
              v-if="scope.row.status === '待审批'"
            >
              审批
            </el-button>
            <el-button 
              type="primary" 
              link
              @click="handleDetail(scope.row)"
            >
              查看
            </el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-card>
  </div>
</template>

<script>
export default {
  name: 'LeaveManagement',
  data() {
    return {
      leaveRecords: [
        {
          name: '张三',
          type: '事假',
          startDate: '2024-03-20 09:00',
          endDate: '2024-03-21 18:00',
          status: '待审批',
          reason: '个人事务处理'
        },
        {
          name: '李四',
          type: '病假',
          startDate: '2024-03-19 09:00',
          endDate: '2024-03-19 18:00',
          status: '已通过',
          reason: '感冒发烧'
        }
      ]
    }
  },
  methods: {
    getLeaveTypeTag(type) {
      const types = {
        '事假': 'info',
        '病假': 'warning',
        '年假': 'success'
      }
      return types[type] || ''
    },
    getStatusTag(status) {
      const types = {
        '待审批': 'warning',
        '已通过': 'success',
        '已拒绝': 'danger'
      }
      return types[status] || ''
    },
    handleAdd() {
      this.$message.success('打开新增请假表单')
    },
    handleApprove(row) {
      this.$message.success(`审批 ${row.name} 的请假申请`)
    },
    handleDetail(row) {
      this.$message.info(`查看 ${row.name} 的请假详情`)
    }
  }
}
</script>

<style scoped>
.leave-management {
  padding: 20px;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
</style> 